package com.easy.dn.ui.main.model;

import com.easy.dn.api.Api;
import com.easy.dn.api.ApiService;
import com.easy.dn.bean.ResumeChat;
import com.easy.dn.bean.ResumeDetailBean;
import com.easy.dn.bean.UserExperienceBean;
import com.easy.dn.ui.main.contract.ResumeDetailContract;
import com.easy.dn.utils.DnUtils;

import java.util.List;
import java.util.Map;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by 丁宁
 * on 2017/8/8.
 */

public class ResumeDetailModel implements ResumeDetailContract.Model {
    @Override
    public Observable<ResumeDetailBean> getResumeDetailData(Map<String, String> map) {
        return Api.getInstance()
                .getProxy(ApiService.class)
                .getResumeDetailData(Api.getCacheControl(), map)
                .map(new Func1<ResumeDetailBean, ResumeDetailBean>() {
                    @Override
                    public ResumeDetailBean call(ResumeDetailBean resumeDetailBean) {
                        //根据地点 行业ID 获取对应的行业名称
                        resumeDetailBean.setAddressStr(DnUtils.getAddressStr(resumeDetailBean.getCity()));
                        resumeDetailBean.setTradeStr(DnUtils.getProfessionTypeStr(resumeDetailBean.getTradeTypeIds()));
                        resumeDetailBean.setJobTypeStr(DnUtils.getJobTypeStr(resumeDetailBean.getJobTypeIds()));
                        resumeDetailBean.setPropertyStr(DnUtils.getPropertyStr(resumeDetailBean.getProperty()));
                        resumeDetailBean.setExceptionalStr(DnUtils.getExceptionalStr(resumeDetailBean.getApplyIntention()));
                        resumeDetailBean.setUserTypeStr(DnUtils.getUserTypeStr(resumeDetailBean.getUserType()));

                        List<UserExperienceBean> exps = resumeDetailBean.getExps();
                        for (UserExperienceBean usrexp : exps) {
                            usrexp.setTradeStr(DnUtils.getProfessionTypeStr(usrexp.getTradeTypeId()));
                            usrexp.setJobTypeStr( DnUtils.getJobTypeStr(usrexp.getJobTypeId()));
                        }
                        return resumeDetailBean;
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    @Override
    public Observable<ResumeChat> getIsChat(Map<String, String> map) {
        return Api.getInstance()
                .getProxy(ApiService.class)
                .getIsChat(Api.getCacheControl(), map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
}
